var express = require('express');
var router = express.Router();
const fs = require('fs');
const path = require('path');
const {getEndLog} = require('../src/utils');
const { basePath,status ,helpList} = require('../src/config');
/* GET home page. */
router.get('/', function(req, res, next) {
  let androidSDK =  fs.readdirSync(path.resolve(basePath,'baseAndroidSDK')).filter(item=>item != '.DS_Store')
  // 数组里面取Android开头的目录
  androidSDK = androidSDK.filter(item=>{
    return item.indexOf('Android') != -1
  })[0]
  if(androidSDK == '_sdkVersion') androidSDK = '--请上传AndroidSDK'
  let iosSDK = fs.readdirSync(basePath+'/baseIosSDK').filter(item=>item != '.DS_Store')[0]
  if(iosSDK == '_sdkVersion') iosSDK = '--请上传IosSDK'
  res.render('index', { title: 'ABuild',androidSDK,iosSDK }); 
});
router.get('/help', function(req, res, next) {
  
  // res.render('help', { title: 'ABuild-help',helpList:JSON.stringify( helpList)}); 
  res.render('help', { title: 'ABuild-help', helpList}); 

});
router.get('/endLog', function(req, res, next) {
  let {projectName} = req.query;
  let result = getEndLog(projectName) || '';
  res.send(status({data:result}) );
}); 

module.exports = router;
